package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.zzyl.entity.User;
import com.zzyl.mapper.UserMapper;
import com.zzyl.vo.UserAuth;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.stereotype.Service;

/**
 * @Description UserDetailsServiceImpl
 * @Author chenchuang
 * @Date 2024-09-05
 */
@Service
public class UserDetailsServiceImpl implements UserDetailsService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public UserDetails loadUserByUsername(String username) {
        User user = userMapper.findUserVoForLogin(username);
        if (null == user || user.getDataState().equals("1")) {
            throw new RuntimeException("用户登录失败");
        }
        return BeanUtil.toBean(user, UserAuth.class);
    }
}
